package at.ac.tuwien.dse.health.entity;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Contains common user attributes.
 *
 * @author Bernhard Nickel
 * @author Gregor Schauer
 * @author Dominik Strasser
 */
@MappedSuperclass
public abstract class User implements Serializable {
	private Long id;
	private Character sex;
	private String firstname;
	private String lastname;
	private String title;

	@Override
	public String toString() {
		return (title != null ? (title + " ") : "") + firstname + " " + lastname;
	}

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Basic(optional = false)
	@Column(length = 1)
	public Character getSex() {
		return sex;
	}

	public void setSex(Character sex) {
		this.sex = sex;
	}

	@Basic(optional = false)
	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	@Basic(optional = false)
	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof User)) {
			return false;
		}

		User user = (User) o;

		return getClass() == o.getClass() && id.equals(user.id);
	}

	@Override
	public int hashCode() {
		return id.hashCode();
	}
}
